#include "filebitreverser.h"
#include <QDebug>

FileBitReverser::FileBitReverser(QObject *parent) : QObject(parent)
{

}

void FileBitReverser::reverse(QString inPath, QString outPath)
{
    QFile in(inPath), out(outPath);
    if(!in.exists()){
        return;
    }
    if(!in.open(QFile::OpenModeFlag::ReadOnly)){
        qWarning() << "cannot open: " << in.fileName();
    }
    if(!out.open(QFile::OpenModeFlag::WriteOnly)){
        qWarning() << "cannot open: " << out.fileName();
    }
    char buff[1024];
    while(true){
        int r = in.read(buff, 1024);
        if(r <= 0){
            break;
        }
        for(int i =0;i<r;i++){
            buff[i] = ~buff[i];
        }
        out.write(buff, r);
    }
    in.close();
    out.close();
}
